package com.zmn.plat.services.impl.supplier;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.pager.LayuiPageUtil;
import com.zmn.plat.model.entity.supplier.ScmSupplier;
import com.zmn.plat.model.entity.supplier.ScmSupplierQuery;
import com.zmn.plat.model.entity.supplier.ScmSupplierVO;
import com.zmn.plat.persistence.interfaces.supplier.ScmSupplierDAO;
import com.zmn.plat.services.interfaces.supplier.ScmSupplierService;

/**
 * @author DaiZhichao
 * @version v1.0 类说明：ScmSupplierServiceImpl
 * @since 2018/10/26 18:02
 */
@Service
public class ScmSupplierServiceImpl implements ScmSupplierService {
    private Logger logger = LoggerFactory.getLogger(ScmSupplierServiceImpl.class);

    @Resource
    private ScmSupplierDAO scmSupplierDAO;

    @Override
    public ScmSupplier findByKey(Integer supplierId) {
        return scmSupplierDAO.findByKey(supplierId);
    }

    @Override
    public ScmSupplierVO findVOByKey(Integer supplierId) {
        return scmSupplierDAO.findVOByKey(supplierId);
    }

    @Override
    public List<ScmSupplier> listPageByQuery(ScmSupplierQuery query) {
        return scmSupplierDAO.listPageByQuery(new LayuiPageUtil<>(query).setLayuiPage().setStartEndTime().getQuery());
    }

    @Override
    public List<ScmSupplierVO> listVOPageByQuery(ScmSupplierQuery query) {
        return scmSupplierDAO.listVOPageByQuery(new LayuiPageUtil<>(query).setLayuiPage().setStartEndTime().getQuery());
    }

    @Override
    public Integer countByQuery(ScmSupplierQuery query) {
        return scmSupplierDAO.countByQuery(new LayuiPageUtil<>(query).setLayuiPageBlank().setStartEndTime().getQuery());
    }

    @Override
    public Integer isDuplicate(String name) {
        return scmSupplierDAO.isDuplicate(name);
    }

    @Override
    public Integer updateByKey(ScmSupplier scmSupplier) {
        scmSupplier.setUpdateTime(DateUtil.getNow());
        return scmSupplierDAO.updateByKey(scmSupplier);
    }

    @Override
    public Integer updateStatus(ScmSupplier scmSupplier) {
        scmSupplier.setUpdateTime(DateUtil.getNow());
        return scmSupplierDAO.updateStatus(scmSupplier);
    }

    @Override
    public Integer updateStatusBatch(StatusDTO dto) {
        dto.setUpdateTime(DateUtil.getNow());
        return scmSupplierDAO.updateStatusBatch(dto);
    }

    /**
     * 描述:修改排序，不会触发updater的更改
     *
     * @param scmSupplier
     *            ScmSupplier
     * @return Integer
     * @author DaiZhichao
     * @since 2018/10/26 12:45
     */
    @Override
    public Integer updateSort(ScmSupplier scmSupplier) {
        return scmSupplierDAO.updateSort(scmSupplier);
    }

    @Override
    public Integer insert(ScmSupplier scmSupplier) {
        scmSupplier.setSupplierId(null);
        scmSupplier.setUpdateTime(DateUtil.getNow());
        scmSupplier.setCreater(scmSupplier.getUpdater());
        scmSupplier.setCreateTime(scmSupplier.getUpdateTime());

        return scmSupplierDAO.insert(scmSupplier);
    }

    @Override
    public Integer deleteByKey(Integer skuId) {
        return scmSupplierDAO.deleteByKey(skuId);
    }

}
